﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace CSMF
{
    public partial class PostPointHandler : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod]
        public static PostResult Post(int Score, int ObjId, int ObjTypeId)
        {

            var _webWorkContext = new WebWorkContext();
            var user = _webWorkContext.CurrentUser;
            if (!user.IsRegistered())
            {
                return new PostResult()
                {
                    Status = "fail",
                    Message = "请先登录"
                };
            }


            var pointService= new PointService();

            var old = pointService.GetPoint(user.Id, ObjId, ObjTypeId);
            if (old != null)
            {
                return new PostResult()
                    {
                        Status = "fail",
                        Message = "您已经评过分了！"
                    };
            }
            pointService.PostPointScore(user.Id,  ObjId, (ObjType)ObjTypeId,Score);


            if ((ObjType)ObjTypeId == ObjType.微力十足)
            {
                var video = VideoInfoManager.GetVideoInfoByID(ObjId);
                var link = ConfigurationManager.AppSettings["AppDomain"] +
                           string.Format("MerakDetail.aspx?id={0}", ObjId);

                var content = string.Format("标题:{0} 链接: {2} 评分:{1}", video.Title, Score, link);

                var _sinaService = new SinaService();
                _sinaService.PostToWeibo(user.Id, content);
            }

            if ((ObjType)ObjTypeId == ObjType.市长带你游)
            {
                var video = MayorManager.GetMayorByID(ObjId);

                var link = ConfigurationManager.AppSettings["AppDomain"] +
                          string.Format("MayorDetail.aspx?id={0}", ObjId);

                var content = string.Format("标题:{0} 链接: {2}  评分:{1}", video.Title, Score, link);
                var _sinaService = new SinaService();
                _sinaService.PostToWeibo(user.Id, content);
            }

            if ((ObjType)ObjTypeId == ObjType.媒体中心新闻)
            {
                var video = NewsInfoManager.GetNewsInfoByID(ObjId);
                var link = ConfigurationManager.AppSettings["AppDomain"] +
                       string.Format("NewsDetail.aspx?id={0}", ObjId);
                var content = string.Format("标题:{0} 链接: {2} 评分:{1}", video.Title, Score, link);
                var _sinaService = new SinaService();
                _sinaService.PostToWeibo(user.Id, content);
            }

            if ((ObjType)ObjTypeId == ObjType.主题活动)
            {
                var video = NewsInfoManager.GetNewsInfoByID(ObjId);
                var link = ConfigurationManager.AppSettings["AppDomain"] +
                         string.Format("ThemeDetail.aspx?id={0}", ObjId);
                var content = string.Format("标题:{0} 链接: {2} 评分:{1}", video.Title, Score, link);
                var _sinaService = new SinaService();
                _sinaService.PostToWeibo(user.Id, content);
            }
            

            return new PostResult()
            {
                Status = "success"
            };
        }
    }
}